<template>
	<view class="wrap-container">
		<view>
			<uni-nav-bar
				fixed
				title="需求详情"
				status-bar
				left-icon="left"
				background-color="#2163e0"
				color="#fff"
				@clickLeft="back" />
			<view class="content-wrap">
				<view class="title"> {{ details.hyDemandPage.demandTitle }}</view>
				<view class="content">{{ details.hyDemandPage.demandContent }}</view>
				<view class="desc-list">
					<view class="desc-item">
						<view class="label">需求部门： {{ details.departName }}</view>
					</view>
					<view class="desc-item">
						<view class="label"
							>联系方式：{{ details.hyDemandPage.phone }}</view
						>
					</view>
					<view class="desc-item">
						<view class="label"
							>有效期至：{{ details.hyDemandPage.effectiveTime }}</view
						>
					</view>
					<view class="desc-item">
						<view class="label">
							{{ "需求状态：" }}
							<text v-show="details.hydynamic.demandStatus == '0'">
								{{ "未开始" }}
							</text>
							<text v-show="details.hydynamic.demandStatus == '1'">
								{{ "进行中" }}
							</text>
							<text v-show="details.hydynamic.demandStatus == '2'">
								{{ "已完成" }}
							</text>
							<text v-show="details.hydynamic.demandStatus == '3'">
								{{ "被驳回" }}
							</text>
							<text v-show="details.hydynamic.demandStatus == '4'">
								{{ "已取消" }}
							</text>
						</view>
					</view>
				</view>
			</view>
			<view>
				<uni-popup ref="popup" background-color="#fff">
					<view>
						<view class="popup-title">驳回需求</view>
						<view style="margin-top: 10px">
							<uni-easyinput
								type="textarea"
								v-model="value"
								placeholder="请输入内容">
							</uni-easyinput>
						</view>
						<view style="margin-top: 10px">
							<button type="primary" @click="submit">提交</button>
						</view>
					</view>
				</uni-popup>
			</view>
			<view class="btn" v-if="status && details.hydynamic.demandStatus == '0'">
				<view><button type="primary" @click="accept">接受提交</button></view>
				<view><button @click="toggle('center')">驳回需求</button></view>
				
			</view>
			<view v-else>
				<downDetail :sendId="details"></downDetail>
			</view>
		</view>
	</view>
</template>
<script>
import api from "../../api/api";
export default {
	name: "taskDetails",
	components: {},
	props: {
		refresh: {
			type: Function,
			default: null,
		},
		backOf: {
			type: Function,
			default: null,
		},
		dettail: {
			type: Object,
			default: {},
		},
	},
	data() {
		return {
			details: this.dettail,
			type: "center",
			value: "",
			status: true,
		};
	},
	// 计算属性 适配者模式
	computed: {},
	// 数据监听
	watch: {},
	/**
	 * 生命周期 类似 发布订阅者模式
	 */
	//监听页面初始化，其参数同 onLoad 参数 触发时机早于 onLoad 百度小程序
	//onInit() {},
	/** 监听页面加载
	 * 其参数为上个页面传递的数据，
	 * 参数类型为 Object（用于页面传参）
	 */
	onLoad() {},
	// 监听页面显示。页面每次出现在屏幕上都触发 包括从下级页面点返回露出当前页面
	onShow() {},
	// 监听页面初次渲染完成 注意如果渲染速度快，会在页面进入动画完成前触发
	onReady() {},
	// 监听页面隐藏
	onHide() {},
	// 监听页面卸载
	onUnload() {},
	methods: {
		back() {
			this.backOf();
		},
		toggle(type) {
			this.type = type;
			this.$refs.popup.open(type);
		},
		submit() {
			var data = { ...this.dettail };
			data.hydynamic.reject = this.value;
			data.hydynamic.demandStatus = 3;
			delete data.hyDemandPage;
			delete data.departName;
			var apiData = { ...data.hydynamic };
			api.edit(apiData).then((e) => {
				if (e.data.success) {
					uni.showToast({
						title: "提交成功",
						icon: "success",
						duration: 1000,
					});
					this.$refs.popup.close();
					this.back();
					this.refresh();
				}
			});
			
		},
		accept() {
			this.status = false;
			var data = {
				id: this.dettail.hydynamic.id,
				demandStatus: '1',
			};
			api.edit(data).then((e) => {
				if (e.data.success) {
					this.refresh();
				}
			});
			var demandData = {
				id: this.dettail.hydynamic.demandId,
				demandStatus: '1',
			};
			api.editDemand(demandData).then((e) => {
				if (e.data.success) {
					//this.refresh();
				}
			});
		},
	},
};
</script>
<style lang="scss" scoped>
.wrap-container {
	position: relative;
	width: 100vw;
	height: 100vh;
	background-color: #fff;
	.content-wrap {
		width: 100%;
    padding: 10px;
		.title {
      font-size: 22px;
			font-weight: 700;
      margin-bottom: 10px;
		}
    .content {
      margin-bottom: 10px;
    }
		.desc-list {
			margin-top: 30px;

			.desc-item {
				width: 100%;
				display: flex;
				justify-content: space-around;
				margin-top: 5px;
				view {
					text-align: left;
					width: 100%;
				}
			}
		}
	}
	.btn {
		position: absolute;
		width: 100vw;
		bottom: 10px;
		display: flex;
		justify-content: space-around;
		view {
			width: 30vw;
		}
	}
	::v-deep .uni-popup__wrapper-box {
		width: 70vw;
		padding: 10px;
		text-align: center;
		background-color: #fff !important;
	}
}
</style>
